package org.example;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

@Configuration
public class AppConfig {

    // 配置一个 ThreadPoolExecutor 作为 Spring Bean
    @Bean
    public ExecutorService executorService() {
        return new ThreadPoolExecutor(
                2, 4,                        // 核心线程数2，最大线程数4
                60L, TimeUnit.SECONDS,       // 线程存活时间
                new LinkedBlockingQueue<>()  // 阻塞队列
        );
    }

    // 配置一个任务 Bean
    @Bean
    public TaskRunner taskRunner() {
        return new TaskRunner();
    }
}
